package com.lsh.dao;

import com.lsh.domain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * 注册业务
 * 持久层操作
 * @author Administrator
 * @date 2019/11/07 21:49
 */
@Repository
public interface RegisterDao {

    // 查询是否已存在该邮箱的记录
    @Select("SELECT count(*) FROM users WHERE email = #{email}")
    int findUserByEmail(String email);

    // 查询是否已存在该用户名的记录
    @Select("SELECT count(*) FROM users WHERE username = #{username}")
    int findUserByUsername(String username);

    // 添加用户信息表
    @Insert("insert into users (username, password, mobile, email)" +
            " values (#{username}, #{password}, #{mobile}, #{email}) ")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insertUserByUser(User user);

    // 查询是否已存在该手机号码的记录
    @Select("SELECT count(*) FROM users WHERE mobile = #{phone}")
    int findUserByPhone(String phone);
}
